// 在Raect中，组件名必须大写

// 引入路由相关 Routes(规则)
import { HashRouter, BrowserRouter, Route, Routes, Link } from "react-router-dom"
// 引入组件
import Login from "./pages/login/index";
import Layout from "./pages/layout/index";
import Dashboard from "./pages/dashboard/index"
import User from "./pages/user/index"
import Good from "./pages/good/goodList"
import GoodList from "./pages/good/goodList";


import { asyncRoutes } from "./pages/index.jsx";
import layout from "./pages/layout/index";

function creatRoutes(accessRoutes) {
    let result = [];
    accessRoutes.forEach(route => {
        if (route.path && route.element) {
            result.push(
                <Route key={route.key} path={route.path} element={route.element}></Route>
            )
        }
        if (route.children) {
            route.children.forEach(route => {
                result.push(
                    <Route key={route.key} path={route.path} element={route.element}></Route>
                )
            })
        }

    });
    return result

}

function App() {
    return (
        <HashRouter>
            <Routes>
                {/* <Link to='/'></Link>
        <Link to='/login'></Link>
        <Link to='/dashboard'></Link>
        <Link to='/user'></Link>
        <Link to='/goodlist'></Link> */}
                <Route path='/' element={<Layout />}>
                    {/* <Route path="/" element={<Layout/>}></Route>
            <Route path="/login" element={<Login/>}></Route>
            <Route path="/dashboard" element={<Dashboard/>}></Route>
            <Route path="/user" element={<User/>}></Route>
            <Route path="/goodlist" element={<GoodList/>}></Route> */}

                    {
                        creatRoutes(asyncRoutes)
                    }
                </Route>
                <Route path="/login" element={<Login />}></Route>
            </Routes>
        </HashRouter>
    );
}
export default App;
